// CommWithClient.h: interface for the CommWithClient class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_COMMWITHCLIENT_H__DDE295F6_25B2_456F_9B0B_F7238522E28A__INCLUDED_)
#define AFX_COMMWITHCLIENT_H__DDE295F6_25B2_456F_9B0B_F7238522E28A__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#define WM_APP_CONNECTED          (WM_APP+1)
#define WM_APP_DISCONNECTED       (WM_APP+2)
#define WM_APP_RECEIVED           (WM_APP+3)
#define WM_APP_EXITSOCKETTHREAD   (WM_APP+4)
#define WM_APP_SENDTO             (WM_APP+5)

class CListeningSocket;
class CServerSocketThread;
class Packet;

class CommWithClient
{
protected:
	CommWithClient();
	virtual ~CommWithClient();

public:
	static CommWithClient * Instance();
	static void DeleteInstance();

	void StartUp(int nPort);
	void ShutDown();
	bool SendTo(const Packet& packet, HANDLE hClient);
	bool Receive(Packet& pPacket, HANDLE hClient);
	bool PostNotification(UINT message, HANDLE hClient, DWORD dwIPAddr = 0);
	bool SendNotification(UINT message, HANDLE hClient, DWORD dwIPAddr = 0);
	void SetpWnd(CWnd * pWnd) {m_pWnd = pWnd;}
	void DeleteThreadBySocket(HANDLE hSocket);

public:
	std::list<CServerSocketThread *> m_Threads;
	CMutex m_mutexThreads;
	bool m_bStop;

protected:
	CListeningSocket * m_pListeningSocket;
	CWnd * m_pWnd;

private:
	static CommWithClient * m_pInstance;
};

#endif // !defined(AFX_COMMWITHCLIENT_H__DDE295F6_25B2_456F_9B0B_F7238522E28A__INCLUDED_)
